<?php

namespace App\Repository\Main;

use App\Repository\BaseRepository;
use App\Repository\UpThree\MainOrderRepostition;
use App\Repository\UpThree\BigDataRepostition;
use App\Repository\UpThree\GetThreeOrderRepostition;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use App\Repository\UpThree\VerificOrderRepository;



class BigDataRepository extends  BaseRepository
{
  private $log;
  public function __construct()
  {
    $this->log = new Logger('mainBigData');
    $this->log->pushHandler(
      (new RotatingFileHandler(storage_path('/logs/mainBigData.log'), 14, Logger::DEBUG, true, 0777))->setFormatter(new LineFormatter(null, null, true, true))
    );
    parent::__construct();
  }
  //异步信息 全部都需要走这个地方 
  public function sendOrder($data = array(), $type = '')
  {
    // 都需要对应成功或失败
    $res = [];
    switch ($type) {
      case 'missOrderDouyin':
        //系统漏单抓取  暂不运行
        $model = new GetThreeOrderRepostition();
        $res = $model->getMissingOrder($data);
        break;
      case 'douyinFail':
        // 需要运行
        // 抖音退款 10分钟跑一次 跑不动 会报错
        // $this->log->info('douyinFail的时间' . time());
        $model = new BigDataRepostition();
        $res = $model->douyinSendDeliverDail($data);
        break;
      case 'pushManual':
        // 手动推送信息  暂不运行
        $model = new BigDataRepostition();
        $res = $model->pushManual($data);
        break;
      case 'verificDouYin':
        // 运行  抖音的数据验证
        $model = new BigDataRepostition();
        $res = $model->verificDouYin($data);
        break;
      case 'updateOrderStatus':
        // 订单状态 定时更新  暂不运行
        $model = new BigDataRepostition();
        $res = $model->updateOrderStatus($data);
        break;
      case 'handDouYinCathSendOrder':
        // 抖音抓单表同步到订单 暂不运行
        $model = new BigDataRepostition();
        $res = $model->handDouYinCathSendOrder($data);
        break;
      case 'tableDatas':
        // 图标数据 暂不运行
        $model = new BigDataRepostition();
        $res = $model->createMoreStatist($data);
        break;
      case 'getOrderStatusEdit':
        $models = new VerificOrderRepository();
        $res = $models->getOrderStatusEdit($data);
        break;
      case 'createStockStistict':
        $model = new BigDataRepostition();
        $res = $model->createStockStistict($data);
        break;
      case 'autoGetGoodsPhoneConfig':
        $model = new \App\Repository\GoodsPhone\AutoGoodsPhoneRepository();
        $res = $model->getPhoneConfig($data);
        break;
      case 'autoGetGoodsPhone':
        $model = new \App\Repository\GoodsPhone\AutoGoodsPhoneRepository();
        $res = $model->getAutoPhone($data['product_id'],$data);
        break;
    }
    $this->log->info('类型:' . $type . '参数:' . json_encode($data) . '返回的结果:' . json_encode($res));
    if (empty($res['code']) || $res['code'] != 200) {
      // 这个地方可以重新提交
    }
    return $res;
  }
  // 大文件的读取和设置
  public function longFile($data = array(), $type = '')
  {
    // $data = [
    //   'file_name' => '',
    // ];
    // 排队处理
    switch ($type) {
      case 'smsMore':
        break;
      case 'createOrder':
        break;
    }
  }
  // 订单成功
  public function createOrder()
  {
    // 将订单提交到第三方

  }
  // 订单失败
  public function createOrderFail()
  {
  }
  // 订单状态处理
  public function orderStatus()
  {
    // 判断是否发送短信
    // 判断是否推送信息
    // 判断是否发送给另外个代理商
  }
  // 订单状态失败处理
  public function orderStatusFail()
  {
  }
  // 抓取订单成功
  public function catchOrder()
  {
  }
  // 抓取订单失败
  public function catchOrderFail()
  {
  }
  // 发送短信成功
  public function sendSms()
  {
  }
  // 发送短信失败
  public function sendSmsFail()
  {
  }
  // 推送订单
  public function pushOrder()
  {
  }
  // 推送订单失败
  public function pushOrderFail()
  {
  }
}
